import java.math.BigDecimal;
import java.math.MathContext;

public class t679 {
    static boolean flag = false;

    public static void main(String[] args) {
        int cards[] = {1,2,1,2};
        boolean a = judgePoint24(cards);
        System.out.println(a);
    }

    public static boolean judgePoint24(int[] cards) {
        double arr[] = new double[4];
        for (int i = 0; i < 4; i++) {
            arr[i] = cards[i];
        }
        for (int i = 0; i < 4; i++) { //a
            for (int j = 0; j < 4; j++) { //b
                if (i == j) continue;
                for (int k = 0; k < 4; k++) { //c
                    if (i == k || k == j) continue;
                    for (int p = 0; p < 4; p++) { //d
                        if (i == p || j == p || k == p) continue;
                        double a = arr[i];
                        double b = arr[j];
                        double c = arr[k];
                        double d = arr[p];
                        count(a, b, c, d);
                        if (flag) {
                            return true;
                        }

                    }
                }
            }
        }

        return false;
    }

    public static void count(double a, double b, double c, double d) {
        double num = 0;
        num = a + b + c + d;flag(num);
        num = a - b + c + d;flag(num);
        num = a * b + c + d;flag(num);
        num =a * b + c - d;flag(num);
        num = a * b - c - d;flag(num);
        num = a * (b + c) + d;flag(num);
        num = a * (b + c) - d;flag(num);
        num = a * (b - c) - d;flag(num);
        num = a * (b - c) + d;flag(num);
        num = a * (b + c + d);flag(num);
        num = a * (b + c - d);flag(num);
        num = a * (b - c - d);flag(num);
        num = a * b * c + d;flag(num);
        num = a * b * c - d;flag(num);
        num = a * b * (c + d);flag(num);
        num =a * b * (c - d);flag(num);
        num = (a + b) * (c + d);flag(num);
        num = (a - b) * (c - d);flag(num);
        num = (a + b) * (c - d);flag(num);
        num =  a * (b - c * d);flag(num);
        num = a * (b + c * d);flag(num);
        num = a * b / (c + d);flag(num);
        if((c-d)!=0)
        num = a * b / (c - d);flag(num);
        num = a * (b - c / d);flag(num);
        if((b - c / d)!=0)
        num = a * (b + c / d);flag(num);
        if((b - c / d)!=0)
        num = a / (b - c / d);flag(num);
    }

    public static void flag(double num) {
        BigDecimal b1 = new BigDecimal(num, new MathContext(2));
        //System.out.println(b1);
        if (b1.equals(new BigDecimal("24"))) {
            flag = true;
        }
    }

}
